document.getElementById('getButton').addEventListener('click', getData);
document.getElementById('postButton').addEventListener('click', postData);

function getData () {
  axios.get('https://jsonplaceholder.typicode.com/posts/1')
    .then(response => {
      displayResult('GET Response:', response.data);
    })
    .catch(error => {
      displayResult('Error:', error.message);
    });


}


function postData () {
  axios.post('https://jsonplaceholder.typicode.com/posts', {
    title: 'foo',
    body: 'bar',
    userId: 1
  })
    .then(response => {
      displayResult('POST Response:', response.data);
    })
    .catch(error => {
      displayResult('Error:', error.message);
    });
}

function displayResult (title, data) {
  const resultDiv = document.getElementById('result');
  resultDiv.innerHTML = `<h2>${title}</h2><pre>${JSON.stringify(data, null, 2)}</pre>`;
}